/*主模块启动操作类
Created on 2020年05月10日
@author: zxyong 13738196011
 */

package com.zxy.main;

import java.util.Timer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import com.zxy.common.Com_Para;
import com.zxy.tcp.ClientThread;
import com.zxy.tcp.CustTimeTask;
import com.zxy.tcp.SelfTimeTask;
import com.zxy.tcp.ServerThread;
import com.zxy.tcp.ServerThreadHttp;

public class ServerMain extends HttpServlet
{
	private static final long	serialVersionUID	= 1L;

	public void init() throws ServletException
	{
		super.init();
		System.out.println("CenterDataInter Main开始");
		try
		{
			Init_Page.Init_Load();
		}
		catch(Exception es)
		{
			es.printStackTrace();
		}
		// 是否启用http协议接口
		if(Com_Para.bThread == true)
		{
			ServerThreadHttp athttp = new ServerThreadHttp("","");
			athttp.start();
		}
		// 中转节点Node客户端
		if(Com_Para.If_Child_Device == 1)
		{
			ClientThread st = new ClientThread();
			st.start();
		}
		// 中转节点Node服务端
		if(Com_Para.If_Parent_Device == 1)
		{
			ServerThread at = new ServerThread("","");
			at.start();
		}

		/**** Session计时和删除数据 ***/
		Timer time2 = new Timer();
		SelfTimeTask sthreadT = new SelfTimeTask();
		time2.scheduleAtFixedRate(sthreadT,3000,30000);

		// 自定义定时器
		int iIndex = 0;
		for(String num: Com_Para.CustTimeTaskNum.split(";"))
		{
			// 默认24小时
			int iLoop = 86400000;
			try
			{
				iLoop = Integer.valueOf(num);
			}
			catch(Exception es)
			{
			}
			Timer CustTime = new Timer();
			CustTimeTask ctt = new CustTimeTask();
			ctt.REFLECT_IN_CLASS = Com_Para.CustTimeREFLECT_IN_CLASS.split(";").length > iIndex ? Com_Para.CustTimeREFLECT_IN_CLASS.split(";")[iIndex] : "";
			CustTime.scheduleAtFixedRate(ctt,3000,iLoop);
			iIndex++;
		}
		System.out.println("CenterDataInter Main结束");
	}
}